package valueobj;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import uk.ac.nott.cs.g53dia.Bee;
import uk.ac.nott.cs.g53dia.Cell;
import uk.ac.nott.cs.g53dia.Environment;
import uk.ac.nott.cs.g53dia.Nest;
import uk.ac.nott.cs.g53dia.Point;
import utils.Constants;

public class GlobalState {
	private Map<Point, Cell> cells;
	private Map<Point, Cell> cellsVisited;
	private Map<Bee, Point> bees;
	private List<Bee> swarm;
	
	public GlobalState(List<Bee> swarm, Environment env) {
		cells = new HashMap<Point, Cell>();
		cellsVisited = new HashMap<Point, Cell>();
		bees = new HashMap<Bee, Point>();
		this.swarm = swarm;
		for (int i = 0; i < Constants.GS_INITIAL_X; i++) {
			for (int j = 0; j < Constants.GS_INITIAL_Y; j++) {
				Point p = new Point(Constants.GS_INITIAL_X_MIN + i, Constants.GS_INITIAL_Y_MIN + j);
				cells.put(p, env.getCell(p));
			}	
		}
	}
	
	public void addInformation(Bee bee, Map<Point, Cell> cells) {
		this.bees.put(bee, bee.getPosition());
		for (Point p : cells.keySet()) {
			boolean isIn = this.cellsVisited.keySet().contains(p);
			if (isIn && !(this.cellsVisited.get(p) instanceof Nest) && (cells.get(p) instanceof Nest)) {
				this.cellsVisited.put(p, cells.get(p)); // new nest
			} if (!isIn) {
				this.cellsVisited.put(p, cells.get(p)); // new cell
			}
		}
	}

	public Map<Point, Cell> getCells() {
		return cells;
	}

	public void setCells(Map<Point, Cell> cells) {
		this.cells = cells;
	}

	public Map<Point, Cell> getCellsVisited() {
		return cellsVisited;
	}

	public void setCellsVisited(Map<Point, Cell> cellsVisited) {
		this.cellsVisited = cellsVisited;
	}

	public Map<Bee, Point> getBees() {
		return bees;
	}

	public void setBees(Map<Bee, Point> bees) {
		this.bees = bees;
	}

	public List<Bee> getSwarm() {
		return swarm;
	}

	public void setSwarm(List<Bee> swarm) {
		this.swarm = swarm;
	}

}
